﻿using System;
using System.Diagnostics;
using System.Configuration;
using Famofo.AgbaraVOIP.Rest.FreeSwitch;
using Nancy;
using Nancy.Hosting.Self;
namespace AgbaraVOIP.Rest
{
    class Program
    {
        static string rest_server_address = string.Empty;
        static void Main(string[] args)
        {
            AppSettingsReader reader = new AppSettingsReader();
            rest_server_address = (string)reader.GetValue("Rest_Server_Address", rest_server_address.GetType());
            var nancyHost = new NancyHost(new Uri(rest_server_address));
            nancyHost.Start();
            Console.WriteLine("Started Server at {0}", rest_server_address);
            Console.WriteLine("AgbaraVOIP API Server  now listening on {0}. Press enter to stop", rest_server_address);
            Process.Start(rest_server_address);
            var apiserver = new RestServer();
            try
            {
                apiserver.start();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                apiserver.stop();
            }

            nancyHost.Stop();
            apiserver.stop();
            Console.WriteLine("Stopped. Good bye!");

        }
    }
}

